﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="news_newsadd.aspx.cs" Inherits="backmanage_newssystem_news_newsadd" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>发布新闻</title>
    <script type="text/javascript" src="../js/jquery-1.6.1.js"></script>
    <script type="text/javascript" src="../xheditor/xheditor-1.1.8-zh-cn.min.js"></script>
    <script type="text/javascript" src="../js/jquery.query.get.js"></script>
    
    <script type="text/javascript">
    $(function(){
           $("#newseditor").xheditor({
                         tools:'mfull',
                         skin:'default',
                         width:'300',
                         height:'200',
                         upBtnText:'上传',
                         upImgUrl:'../API/A_UpImg.aspx',
                         upImgExt:'jpg,jpeg,gif,png,bmp',
           });
           var hot=0;
           function checkSelect()
           {
                     var c=$("input:checked");
                     var b=new Array();
                     for(var i=0;i<c.length;i++)
                     {
                           var flag=true;
                           flag=flag && c[i].value=="hot";
                           if(flag)
                           {
                             hot=1;
                           }
                     }
           }
           function NewsAdd()
           {
                         checkSelect();
                         var ti=$("#title").val();
                         var cl=$("#idlist").find("option:selected").attr("value");
                         var key=$("#keyword").val();
                         var su=$("#subtitle").val();
                         var ab=$("#abstract").val();
                         var au=$("#author").val();
                         var from=$("#isfrom").val();
                         var co=escape($("#newseditor").val());
                         $.ajax({
                                 async:false,
                                 url:'../API/A_News.aspx',
                                 type:'POST',
                                 data:{edit:'add',
                                       title:ti,
                                       classid:cl,
                                       keyword:key,
                                       subtitle:su,
                                       abstracr:ab,
                                       author:au,
                                       isfrom:from,
                                       content:co,
                                       ishot:hot
                                 },
                                 success:function(msg)
                                 {
                                    alert(msg);
                                 }
                         })
           }
           function NewsUpdate(id)
           {
                         var flag=false;
                         checkSelect();
                         var ti=$("#title").val();
                         var cl=$("#idlist").find("option:selected").attr("value");
                         var key=$("#keyword").val();
                         var su=$("#subtitle").val();
                         var ab=$("#abstract").val();
                         var au=$("#author").val();
                         var from=$("#isfrom").val();
                         var co=escape($("#newseditor").val());
                         $.ajax({
                                 async:false,
                                 url:'../API/A_News.aspx',
                                 type:'POST',
                                 data:{edit:'update',
                                       id:id,
                                       title:ti,
                                       classid:cl,
                                       keyword:key,
                                       subtitle:su,
                                       abstracr:ab,
                                       author:au,
                                       isfrom:from,
                                       content:co,
                                       ishot:hot
                                 },
                                 success:function(msg)
                                 {
                                    alert(msg);
                                    flag=true;
                                 }
                         })
                         return flag;
           }
           function ClassList()
           {
              $.ajax({
                     async:false,
                     url:'../API/A_News.aspx',
                     type:'POST',
                     data:{edit:'class'},
                     success:function(msg)
                     {
                        $("#classlist select").text("");
                        $("#classlist select").append(msg);
                     }
              });
           }
           function SetInfo()
           {
             var edit=$.query.get("edit");
             var id=$.query.get("id");
             if(edit=="update")
             {
               $.ajax({
                       async:false,
                       url:'../API/A_News.aspx',
                       type:'POST',
                       data:{edit:"item",id:id},
                       dataType: 'json',
                       success:function(data)
                       {
                         $("#title").val(data.t);
                         $("#idlist").attr("value",data.c);
                         $("#keyword").val(data.k);
                         $("#subtitle").val(data.s);
                         $("#abstract").val(data.a);
                         $("#author").val(data.au);
                         $("#isfrom").val(data.f);
                         $("#newseditor").val(unescape(data.co));
                         if(data.h=="true")
                         {
                           $("#ishot").attr("checked",true);
                         }
                         else
                         {
                           $("#ishot").removeAttr("checked");
                         }
                         $("#ok").hide();
                         $("#update").show();
                         $("#cancel").show();
                       }
               });
             }
           }
           $("#ok").click(function(){
                         NewsAdd();
           });
           $("#update").click(function(){
                   var id=$.query.get("id");
                   var flag=NewsUpdate(id);
                   if(flag)
                   {
                     window.close();
                   }
           });
           $("#cancel").click(function(){
                   var flag=confirm("关闭此窗口!");
                   if(flag)
                   {
                     window.close();
                   }
           });
           $(document).ready(function(){ClassList();SetInfo();});
    })
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    发布新闻
    <table>
     <tr>
       <td>标题：</td>
       <td><input type="text" id="title" runat="server" /></td>
     </tr>
     <tr id="classlist">
        <td>类别</td>
        <td>
          <select id="idlist" runat="server">
          </select>
        </td>
     </tr>
     <tr>
       <td>关键字：</td>
       <td><input type="text" id="keyword" runat="server" /></td>
     </tr>
     <tr>
       <td>副标题：</td>
       <td><input type="text" id="subtitle" runat="server" /></td>
     </tr>
     <tr>
       <td>摘要：</td>
       <td><input type="text" id="abstract" runat="server" /></td>
     </tr>
     <tr>
       <td>作者：</td>
       <td><input type="text" id="author" runat="server" /></td>
     </tr>
     <tr>
       <td>转载地址：</td>
       <td><input type="text" id="isfrom" runat="server" /></td>
     </tr>
     <tr>
       <td>热点：</td>
       <td><input type="checkbox" id="ishot" value="hot" runat="server" /></td>
     </tr>
     <tr>
       <td>内容：</td>
       <td><textarea id="newseditor" runat="server"></textarea></td>
     </tr>
    </table>
        <input type="button" id="ok" value="提交" />
        <input type="button" id="update" value="修改" style="display:none" />
        <input type="button" id="cancel" value="取消" style="display:none" />
    </div>
    </form>
</body>
</html>
